/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.kz.shange.imgSvc;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
public class ImgServer extends HttpServlet {
 @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("image/jpeg;charset=UTF-8");
        String echo = request.getParameter("img");
        echo = new String(echo.getBytes("ISO-8859-1"), "UTF-8");
        System.out.println(echo);
        
        ServletOutputStream out=response.getOutputStream();
        File file = new File("d:/abc.jpg");
               
        Image img = ImageIO.read(file);
        
        BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);  
        bufferedImage.getGraphics().drawImage(img, 0, 0, null); 
        ImageIO.write(bufferedImage, "jpeg", out);    
    }
}
